package com.tuananh.radnom.model;

import java.util.ArrayList;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "ne-conf")
@XmlType(propOrder = { "listNode", "listConn", "listGroup" })
public class NetElementConfiguration extends AbstractConfiguration {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4912192213968765083L;

	public static String path = "../config/ne-conf.xml";
	static {
		path = DirectoryConfig.configPaths.get(NetElementConfiguration.class
				.getName());
	}
	{
		configPath = path;
	}
	
	static ArrayList<NetNode> listNode;
	static ArrayList<NetConn> listConn;
	static ArrayList<NeGroup> listGroup;
	@XmlElementWrapper(name = "nodes")
	@XmlElement(name = "node")
	public ArrayList<NetNode> getListNode() {
		if (listNode == null)
			listNode = new ArrayList<NetNode>();
		return listNode;
	}

	public void setListNode(ArrayList<NetNode> listNode) {
		NetElementConfiguration.listNode = listNode;
	}

	@XmlElementWrapper(name = "connections")
	@XmlElement(name = "connection")
	public ArrayList<NetConn> getListConn() {
		if (listConn == null)
			listConn = new ArrayList<NetConn>();
		return listConn;
	}

	public void setListConn(ArrayList<NetConn> listConn) {
		NetElementConfiguration.listConn = listConn;
	}

	@XmlElementWrapper(name = "groups")
	@XmlElement(name = "group")
	public ArrayList<NeGroup> getListGroup() {
		if (listGroup == null)
			listGroup = new ArrayList<NeGroup>();
		return listGroup;
	}

	public void setListGroup(ArrayList<NeGroup> listGroup) {
		NetElementConfiguration.listGroup = listGroup;
	}

	// Some convenient method for configurate xml file

	// public synchronized static boolean addNE(NetElement ne) {
	//
	// if (ne.getClass() == NetNode.class) {
	// // check for unique name of an network element
	// for (NetNode node : listNode)
	// if (!node.validate(ne))
	// return false;
	// listNode.add((NetNode) ne);
	// return true;
	// } else if (ne.getClass() == NetConn.class) {
	// // check the validation of the new connection
	// for (NetConn conn : listConn)
	// if (!conn.validate(ne))
	// return false;
	// listConn.add((NetConn) ne);
	// return true;
	// } else if (ne.getClass() == NetInterface.class) {
	// NetInterface netInt = (NetInterface) ne;
	// for (NetNode node : listNode)
	// if (node.getName().equals(netInt.netNode.getName())) {
	// for (NetInterface nInt : node.getNetInterfaces()) {
	// if (nInt.name.equals(netInt.name))
	// return false;
	// }
	// node.getNetInterfaces().add(netInt);
	// }
	// }
	// return true;
	// }
	//
	// public synchronized static boolean addGroup(NeGroup neGroup) {
	// for (NeGroup gr : listGroup)
	// if (!gr.validate(neGroup))
	// return false;
	// listGroup.add(neGroup);
	// return true;
	// }
	//
	// public synchronized static boolean addConnection(NetConn connection) {
	// for (NetConn conn : listConn)
	// if (!conn.validate(connection))
	// return false;
	// listConn.add(connection);
	// return true;
	// }
	@Override
	public AbstractConfiguration clone() {
		// TODO Auto-generated method stub
//		NetElementConfiguration netConfig = new NetElementConfiguration();
//		netConfig.configPath = configPath.trim();
//		netConfig.listNode = (ArrayList<NetNode>) this.listNode.clone();
//		netConfig.listConn = (ArrayList<NetConn>) this.listConn.clone();
//		netConfig.listGroup = (ArrayList<NeGroup>) this.listGroup.clone();

		return null;
	}
}
